//
//  TCM_AuctionRankViewController.swift
//  TCM_TradingProject
//
//  Created by 吕春海 on 2018/8/29.
//  Copyright © 2018年 lvchunhai. All rights reserved.
//

import UIKit

class TCM_AuctionRankViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

    var autionTableView:UITableView!

    @IBOutlet weak var rankLeadConstraint: NSLayoutConstraint!
    @IBOutlet weak var timeLeadConstraint: NSLayoutConstraint!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "竞拍榜单"
        
        if TCM_ScreenWidth == 320 {
            rankLeadConstraint.constant = 8
            timeLeadConstraint.constant = 8
        } else {
            rankLeadConstraint.constant = 32
            timeLeadConstraint.constant = 32
        }
        
        initialTableView()
        // Do any additional setup after loading the view.
    }
    
    func initialTableView() {
        autionTableView = UITableView(frame: CGRect(x: 0, y: TCM_NavBarHeight() + 40, width: TCM_ScreenWidth, height: TCM_ScreenHeight - TCM_NavBarHeight() - 40), style:.grouped)
        autionTableView.backgroundColor = TCM_HexRGB(0xF0F0F0)
        autionTableView.separatorStyle = UITableViewCellSeparatorStyle.none
        autionTableView.showsVerticalScrollIndicator = false
        autionTableView.delegate = self
        autionTableView.dataSource = self
        
        self.view.addSubview(autionTableView)
    
        autionTableView.register(UINib.init(nibName: "TCM_AuctionRankTableViewCell", bundle: nil), forCellReuseIdentifier: "rankCell")
        
    }
    
    // MARK: -tableview代理
    //设置cell的数量
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    
    //设置section的数量
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 44
    }
    
    //设置tableview的cell
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = (autionTableView.dequeueReusableCell(withIdentifier: "rankCell", for: indexPath)) as! TCM_AuctionRankTableViewCell
        cell.selectionStyle = .none
        if indexPath.row % 2 == 0 {
            cell.bgView.backgroundColor = TCM_HexRGB(0xFBF7F5)

        } else {
            cell.bgView.backgroundColor = UIColor.white
        }
        
        cell.rankNumberLabel.text = "\(indexPath.row + 1)"
        return cell
    }

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0.00001
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return nil
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 35
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let footerView = UIView()
        footerView.frame = CGRect(x: 0, y: 0, width: TCM_ScreenWidth, height: 35)
        footerView.backgroundColor = UIColor.white
        
        let button:UIButton = UIButton(type:.custom)
        //设置按钮位置和大小
        button.frame = CGRect(x: 0, y: 0, width: TCM_ScreenWidth, height: 35)
        //设置按钮文字
        button.setTitle("更多记录", for: .normal)
        button.setTitleColor(TCM_HexRGB(0x693C26), for: .normal)
        button.titleLabel?.font(12)
        footerView.addSubview(button)
        
        
        return footerView
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
